﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region RPTGravelInspection

        public List<tb_RPT_GravelInspection> GetAllGravelInspection()
        {

            var query = (from obj in this.tb_RPT_GravelInspections
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }
        

        public List<tb_RPT_GravelInspection> GetGravelInspectionByContition(string  strSequence ,string strProjectName  
                                                                        ,string  strMaterialOrigin ,string  strTestDate)
        {
            var tq = from obj in this.tb_RPT_GravelInspections
                     where obj.IsDelete == 0
                     select obj;

            if (strSequence.Length > 0)
            {
                tq = tq.Where(entity => entity.Sequence == strSequence);
            }

            if (strProjectName.Length > 0)
            {
                tq = tq.Where(entity => entity.ProjectName == strProjectName);
            }
            if (strMaterialOrigin.Length > 0)
            {
                tq = tq.Where(entity => entity.MaterialOrigin == strMaterialOrigin);
            }
            if (strTestDate.Length > 0)
            {
                tq = tq.Where(entity => entity.TestDate == strTestDate);
            }
            var query = tq.ToList();
            return query;
        }

        public List<tb_RPT_GravelInspection> GetGravelInspectionByProjectName(string strProjectName)
        {

            var query = (from obj in this.tb_RPT_GravelInspections
                         where obj.IsDelete == 0 && obj.ProjectName == strProjectName
                         select obj).ToList();
            return query;
        }

        public tb_RPT_GravelInspection GetGravelInspectionById(int id)
        {
            return this.tb_RPT_GravelInspections.SingleOrDefault(tb_RPT_GravelInspections => tb_RPT_GravelInspections.Id == id);
        }

        public void CreateGravelInspection(tb_RPT_GravelInspection entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_RPT_GravelInspections.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyGravelInspection(tb_RPT_GravelInspection entity)
        {
            tb_RPT_GravelInspection instance = this.tb_RPT_GravelInspections.SingleOrDefault(p => p.Id == entity.Id);
            instance.Sequence = entity.Sequence;
            instance.ProjectName = entity.ProjectName;
            instance.MaterialOrigin = entity.MaterialOrigin;
            instance.TestDate = entity.TestDate;
            instance.ApparentDensity = entity.ApparentDensity;
            instance.StackingDensity = entity.StackingDensity;
            instance.LamellarContent = entity.LamellarContent;
            instance.SiltContent = entity.SiltContent;
            instance.ClodContent = entity.ClodContent;
            instance.Voids = entity.Voids;
            instance.CrushingIndex = entity.CrushingIndex;
            instance.Consistence = entity.Consistence;
            instance.JianJiLiaoReaction = entity.JianJiLiaoReaction;
            instance.HarmfulMaterial = entity.HarmfulMaterial;
            instance.RockCompressive = entity.RockCompressive;
            instance.MEASUResult1 = entity.MEASUResult1;
            instance.MEASUResult2 = entity.MEASUResult2;
            instance.MEASUResult3 = entity.MEASUResult3;
            instance.MEASUResult4 = entity.MEASUResult4;
            instance.MEASUResult5 = entity.MEASUResult5;
            instance.MEASUResult6 = entity.MEASUResult6;
            instance.MEASUResult7 = entity.MEASUResult7;
            instance.MEASUResult8 = entity.MEASUResult8;
            instance.TestStandard = entity.TestStandard;
            instance.TestResult = entity.TestResult;
            instance.Remark = entity.Remark;
            instance.Review = entity.Review;
            instance.Approval = entity.Approval;
            instance.Test = entity.Test; 

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }

        public void DeleteGravelInspection(tb_RPT_GravelInspection entity)
        {
            tb_RPT_GravelInspection deleteEntity = tb_RPT_GravelInspections.SingleOrDefault(p => p.Id == entity.Id);
            tb_RPT_GravelInspections.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }

}
